package com.errorfinding.tabbitmqDemo.consumer;

import cn.hutool.core.date.DateUtil;
import com.errorfinding.tabbitmqDemo.config.DelayedQueueConfig;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.UnsupportedEncodingException;

/**
 * 消费者 基于插件的延迟消息
 */
@Component
public class DelayQueueConsumer {

    //监听消息
    @RabbitListener(queues = DelayedQueueConfig.delayed_queue_name)
    public void receiveDelayQueue(Message message) throws UnsupportedEncodingException {
        String msg = new String(message.getBody(),"UTF-8");
        System.out.println("当前时间："+ DateUtil.date()+"，收到延迟队列的消息是："+msg);
    }
}
